package reflection;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.Objects;

@Getter
@Setter
@ToString
public class Test1 {
    public static void main(String[] args) throws ClassNotFoundException {
        Class c1 = Class.forName("reflection.User");
        System.out.println(c1);
        Class c2 = Class.forName("reflection.User");
        Class c3 = Class.forName("reflection.User");
        System.out.println(c1.hashCode());
        System.out.println(c2.hashCode());
        System.out.println(c3.hashCode());
        System.out.println(c1.equals(c2));
        User u1=new User("张三",18);
        User u2=new User("张三",18);
        System.out.println(u1.equals(u2));
        System.out.println(u1.hashCode());
        System.out.println(u2.hashCode());
        System.out.println(u1.getClass().hashCode() );
    }
}

@ToString
@Getter
@Setter
class User{
    public int a;
    protected int b;
    private String name;
    private int age;
    public User() {}
    public User(String name, int age) {
        this.name = name;
        this.age = age;
    }

    private void a(){}
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        User user = (User) o;
        return age == user.age &&
                Objects.equals(name, user.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }
}
